package net.yihang.miaosha.redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

public class JedisExecutor {

    private JedisPool jedisPool;

    public JedisExecutor(JedisPool jedisPool) {
        this.jedisPool = jedisPool;
    }

    public <T> T exeucte(JedisAction<T> executor, Class<T> resultType) {
        try (Jedis jedis = jedisPool.getResource()) {
            return executor.execute(jedis);
        }
    }

    public void exeucte(JedisAction executor) {
        try (Jedis jedis = jedisPool.getResource()) {
            executor.execute(jedis);
        }
    }
}
